package com.ybu;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.function.Consumer;


/**
 * @ProjectName: shixun
 * @Titile: HashSetDemo
 * @Author: Jie
 * @Description: TODO
 */
public class HashSetDemo {
    public static void main(String[] args){
        ArrayList<String>list = new ArrayList<>();
        list.add("张三");
        list.add("张三");
        list.add("张三");
        list.add("张三");
        System.out.println(list);
        System.out.println(new HashSet<String>(list));

        //1. 创建HashSet对象
        HashSet<String> hashSet = new HashSet<>();
        //2.保存数据
        //可以去重
        hashSet.add("张三");
        hashSet.add("李四");
        hashSet.add("王五");
        hashSet.add("王五");
        hashSet.add("王五");
        hashSet.add("王五");
        hashSet.add("赵六");
        System.out.println(hashSet);
        //3.取数据（迭代器）iterator
        //hasNext判断是否还有数据
        Iterator<String> iterator = hashSet.iterator();
        while (iterator.hasNext()) {
            String next = iterator.next();
            System.out.println(next);
        }
        //4.取数据（增强for循环）
        for (String name : hashSet) {
            System.out.println(name);
        }
        //5.取数据（Lambda）
        hashSet.forEach(new Consumer<String>() {
            @Override
            public void accept(String s) {
                System.out.println(s);
            }
        });

        hashSet.forEach(s -> System.out.println(s));

        hashSet.forEach(System.out::println);


        Student student = new Student("张三", 20);
        //toHexString转化为一个十六进制数
        //native本地

        //toString
        System.out.println(student);



    }
}
